package com.jnzc.ocr.rest.app.shop.controller.app;

import com.jnzc.ocr.common.bean.Page;
import com.jnzc.ocr.common.bean.PageResult;
import com.jnzc.ocr.common.vo.UserVo;
import com.jnzc.ocr.dependencies.rest.base.BaseController;
import com.jnzc.ocr.serv.shop.api.ShopStockApi;
import com.jnzc.ocr.serv.shop.entity.ShopStock;
import com.jnzc.ocr.serv.shop.filter.ShopStockFilter;
import com.jnzc.ocr.serv.shop.vo.ShopCheckCreateVo;
import com.jnzc.ocr.serv.shop.vo.ShopStockCreateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangcm
 * @version 1.0, 2017-09-29
 */
@Api(tags = {"app - 进货接口"})
@RestController
@RequestMapping("/app/stock")
public class AppStockController extends BaseController {

    @Autowired
    private ShopStockApi shopStockApi;

    @ApiOperation(value = "分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "supplierId", value = "供应商ID", required = true, paramType = "query")
    })
    @GetMapping("")
    public PageResult<ShopStock> search(Long supplierId, Page page){
        UserVo userVo = super.get();
        ShopStockFilter filter = new ShopStockFilter();
        filter.setShopId(userVo.getShopId());
        filter.setSupplierId(supplierId);
        return shopStockApi.search(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "保存")
    @PostMapping("")
    public void save(@RequestBody ShopStockCreateVo vo){
        UserVo userVo = super.get();
        shopStockApi.save(vo, userVo.getShopId());
    }
}
